package com.miaow.controller;

import com.miaow.service.MiaowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.*;

/**
 * @author HWZ
 * @date 2023年12月18日 19:27
 * @description
 */
@RestController
public class MiaowController {


    @Autowired
    private MiaowService miaowService;

    private final ExecutorService executorService = Executors.newFixedThreadPool(10);

    @GetMapping("/miaow")
    public String miaow(){
        Future<String> future = executorService.submit(() -> miaowService.yourMethod());
        try {
            return future.get(3, TimeUnit.SECONDS);
        } catch (TimeoutException e) {
            // 超时处理逻辑
            return miaowService.fallbackMethod();
        } catch (InterruptedException | ExecutionException e) {
            // 异常处理逻辑
            return "请求发生异常，请稍后重试";
        }
    }

}
